from typing import List


class Solution:
    def maximumDifference(self, nums: List[int]) -> int:
        ans = -1
        min_val = nums[0]
        for num in nums:
            if num > min_val:
                ans = max(ans, num - min_val)
            min_val = min(min_val, num)
        return ans


if __name__ == "__main__":
    print(Solution().maximumDifference(nums=[7, 1, 5, 4]))  # 4
    print(Solution().maximumDifference(nums=[9, 4, 3, 2]))  # -1
    print(Solution().maximumDifference(nums=[1, 5, 2, 10]))  # 9
